﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tema2_Adabd.BusinessLayer;

namespace Tema2_Adabd
{

    public partial class AdminBrandCat : Form
    {
        private Utilizator utilizator;

        public AdminBrandCat(Utilizator user)
        {
            InitializeComponent();
            utilizator = user;
        }

        private void clkAddBrand(object sender, EventArgs e)
        {
            if (txtBrand.Text == "")
            {
                MessageBox.Show("Nu ati completat campul corespunzator.");
                return;
            }
            try
            {
                utilizator.adaugaBrand(txtBrand.Text);
                MessageBox.Show("Brandul a fost adaugat cu succes.");
                this.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }

        private void clkStergeBrand(object sender, EventArgs e)
        {
            if (txtBrand.Text == "")
            {
                MessageBox.Show("Nu ati completat campul corespunzator.");
                return;
            }
            try
            {
                utilizator.stergeBrand(txtBrand.Text);
                MessageBox.Show("Stergerea brandului a fost efectuata cu succes.");
                this.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }

        private void clkAddCat(object sender, EventArgs e)
        {
            if (txtCat.Text == "")
            {
                MessageBox.Show("Nu ati completat campul corespunzator.");
                return;
            }
            try
            {
                utilizator.adaugaCategorie(txtCat.Text);
                MessageBox.Show("Adaugarea categoriei s-a realizat cu succes.");
                this.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }

        private void clkStergeCat(object sender, EventArgs e)
        {
            if (txtCat.Text == "")
            {
                MessageBox.Show("Nu ati completat campul corespunzator.");
                return;
            }
            try
            {
                utilizator.stergeCategorie(txtCat.Text);
                MessageBox.Show("Stergerea categoriei s-a realizat cu succes.");
                this.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }

        private void clkArataBranduri(object sender, EventArgs e)
        {
            try
            {
                List<string> lista = utilizator.branduriExistente();
                StringBuilder sb = new StringBuilder();
                foreach (var v in lista)
                {
                    sb.Append(v);
                    sb.Append("\r\n");
                }
                MessageBox.Show(sb.ToString());
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }

        private void clkArataCat(object sender, EventArgs e)
        {
            try
            {
                List<string> lista = utilizator.daCats();
                StringBuilder sb = new StringBuilder();
                foreach (var v in lista)
                {
                    sb.Append(v);
                    sb.Append("\r\n");
                }
                MessageBox.Show(sb.ToString());
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }

        private void clkIesire(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
